var t = require("../../../@babel/runtime/helpers/defineProperty"), e = require("../../../@babel/runtime/helpers/createForOfIteratorHelper"), a = getApp();

Page({
    data: {
        language: "",
        good: "",
        order_id: "",
        ratetextshow: [ "极差", "失望", "一般", "满意", "惊喜" ],
        ratetext: "惊喜",
        level: 5,
        comment: "",
        uploadUrl: "upload.uploadPic",
        fileList3: [],
        fileList4: [],
        upNumMaxOther: 0,
        rateInstalltext: "惊喜",
        Installlevel: 5,
        is_score_latitude: !1,
        describeScore: 5,
        deliveryScore: 5,
        serviceScore: 5
    },
    onLoad: function(t) {
        t.order_id && this.setData({
            order_id: t.order_id
        }), t.id && this.setData({
            id: t.id
        }), this.getGoodDetail(), this.getOtherScore();
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    onShareAppMessage: function() {},
    getGoodDetail: function() {
        var t = this, e = a.getNetAddresss("goods.other-info.get-goods");
        a._getNetWork({
            url: e,
            data: {
                id: this.data.id
            },
            showToastIn: !1,
            success: function(e) {
                var s = e.data;
                1 == s.result ? t.setData({
                    good: s.data
                }) : a.tips(s.msg);
            },
            fail: function(t) {}
        });
    },
    getOtherScore: function() {
        var t = this, e = a.getNetAddresss("goods.comment.create-comment-page");
        a._getNetWork({
            url: e,
            showToastIn: !1,
            success: function(e) {
                var a = e.data;
                1 == a.result ? t.setData({
                    is_score_latitude: a.data.is_score_latitude
                }) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    getStar: function(t) {
        var e = t.detail;
        this.setData({
            level: e,
            ratetext: this.data.ratetextshow[e - 1]
        });
    },
    getInstallStar: function(t) {
        var e = t.detail;
        this.setData({
            Installlevel: e,
            rateInstalltext: this.data.ratetextshow[e - 1]
        });
    },
    commentChange: function(t) {
        var e = t.detail;
        this.setData({
            comment: e
        });
    },
    toComment: function(t) {
        var e = t.target.dataset.good, a = this;
        0 == this.data.comment.length ? wx.showModal({
            title: "提示",
            content: "您还没有输入相关的评论内容",
            success: function(t) {
                t.confirm && a._submitData(e);
            }
        }) : this._submitData(e);
    },
    _submitData: function(t) {
        var e = a.getNetAddresss("goods.comment.create-comment"), s = [];
        if (0 != this.data.fileList3.length) for (var i = 0; i < this.data.fileList3.length; i++) s.push(this.data.fileList3[i].url); else s = [];
        s = JSON.stringify(s);
        var o = {
            order_id: this.data.order_id,
            goods_id: t.goods_id,
            order_goods_id: this.data.good.id,
            content: this.data.comment,
            level: this.data.level,
            images: s
        };
        this.data.good.is_install && 1 == this.data.good.is_install && (o.worker_score = this.data.Installlevel), 
        this.data.is_score_latitude && (o.score_latitude = {
            score_latitude_describe: this.data.describeScore,
            score_latitude_delivery: this.data.deliveryScore,
            score_latitude_service: this.data.serviceScore
        }), a._postNetWork({
            url: e,
            showToastIn: !1,
            data: o,
            success: function(t) {
                var e = t.data;
                1 == e.result ? wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1500,
                    success: function() {
                        setTimeout(function() {
                            wx.navigateBack({
                                delta: 1
                            });
                        }, 1500);
                    }
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    onRead_2: function() {
        if (5 == this.data.upNumMaxOther || this.data.upNumMaxOther >= 5) return wx.showToast({
            icon: "none",
            title: "图片数量已达到上限",
            duration: 1500
        }), !1;
        var t = this, s = a.getNetAddresss(this.data.uploadUrl);
        wx.chooseImage({
            count: 5 - this.data.upNumMaxOther,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(a) {
                var i, o = a.tempFilePaths, r = e(o);
                try {
                    for (r.s(); !(i = r.n()).done; ) {
                        var n = i.value;
                        console.log(n), wx.compressImage({
                            src: n,
                            quality: 60,
                            success: function(e) {
                                var a = e.tempFilePath;
                                wx.uploadFile({
                                    url: s,
                                    filePath: a,
                                    name: "file",
                                    formData: {
                                        attach: "upload"
                                    },
                                    success: function(e) {
                                        var s = JSON.parse(e.data);
                                        if (1 == s.result) {
                                            var i = t.data.fileList3, o = t.data.fileList4;
                                            i.push({
                                                url: s.data.img
                                            }), o.push({
                                                url: a
                                            }), t.setData({
                                                upNumMaxOther: t.data.upNumMaxOther + 1,
                                                fileList3: i,
                                                fileList4: o
                                            });
                                        } else wx.showToast({
                                            icon: "none",
                                            title: s.msg,
                                            duration: 1500
                                        });
                                    }
                                });
                            },
                            fail: function(t) {},
                            complete: function(t) {}
                        });
                    }
                } catch (t) {
                    r.e(t);
                } finally {
                    r.f();
                }
            }
        });
    },
    removeImg_1: function(t) {
        var e = t.currentTarget.dataset.index, a = this.data.fileList3, s = this.data.fileList4;
        a.splice(e, 1), s.splice(e, 1), this.setData({
            fileList3: a,
            fileList4: s
        }), this.setData({
            upNumMaxOther: this.data.fileList3.length
        });
    },
    changeOtherScore: function(e) {
        var a = e.target.dataset.param;
        this.setData(t({}, a, e.detail));
    }
});